package com.wuhao.shootclient.ui.activity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.wuhao.shootclient.MainActivity;
import com.wuhao.shootclient.R;
import com.wuhao.shootclient.util.ToastUtils;
import com.wuhao.shootclient.util.UrlHelper;


/**
 * 启动页
 */
public class SplashActivity extends AppCompatActivity implements View.OnClickListener {

   private Button mBt;
    private  boolean mIsSet;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final View view = View.inflate(this, R.layout.activity_splash, null);
        setContentView(view);
         mBt = findViewById(R.id.bt);
        mBt.setOnClickListener(this);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.3f, 0.9f);
        alphaAnimation.setDuration(1000);
        view.startAnimation(alphaAnimation);
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                if (!mIsSet){
                    MainActivity.start(SplashActivity.this);
                    finish();
                }

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });


    }
    @Override
    public void onClick(View v) {
        mIsSet=true;
        ToastUtils.show("wwwwwwwwww");
        EditText text = new EditText(SplashActivity.this);
        text.setInputType(InputType.TYPE_CLASS_NUMBER);
        AlertDialog.Builder builder = new AlertDialog.Builder(SplashActivity.this).setTitle("看看就行了")
                .setView(text).setPositiveButton("点点点点点点点",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                UrlHelper urlHelper = new UrlHelper();
                                urlHelper.SOCKET = "192.168.0."+text.getText().toString();
                                urlHelper.BASE = "http://192.168.0."+text.getText().toString().trim()+":8080/api/";
                                urlHelper.IMAGE = "http://192.168.0."+text.getText().toString()+":8080/";
//                        urlHelper.IP = "192.168.0."+text.getText().toString();
                                MainActivity.start(SplashActivity.this);
                                finish();
                            }
                        });
        builder.create().show();
    }
}
